function! api#floaterm#init() abort
    if !exists('g:loaded_floaterm')
        try
            packadd vim-floaterm
        catch /.*/
            echoerr v:exception
        endtry
    endif
    if exists('g:loaded_floaterm') && g:loaded_floaterm
        let g:floaterm_autoclose = 1
        let g:floaterm_width = 0.9
        let g:floaterm_height = 0.9
        let g:floaterm_keymap_new    = '<F7>'
        let g:floaterm_keymap_prev   = '<F8>'
        let g:floaterm_keymap_next   = '<F9>'
        let g:floaterm_keymap_toggle = '<F12>'
        nnoremap   <silent>   <F7>    :FloatermNew<CR>
        tnoremap   <silent>   <F7>    <C-\><C-n>:FloatermNew<CR>
        nnoremap   <silent>   <F8>    :FloatermPrev<CR>
        tnoremap   <silent>   <F8>    <C-\><C-n>:FloatermPrev<CR>
        nnoremap   <silent>   <F9>    :FloatermNext<CR>
        tnoremap   <silent>   <F9>    <C-\><C-n>:FloatermNext<CR>
        nnoremap   <silent>   <F12>   :FloatermToggle<CR>
        tnoremap   <silent>   <F12>   <C-\><C-n>:FloatermToggle<CR>
        let g:space_keymap = get(g:, 'space_keymap', { 'name': '+space' })
        let g:space_keymap.t = get(g:space_keymap, 't', { 'name': '+toggle' })
        let g:space_keymap.t.t = get(g:space_keymap.t, 't', [ ':FloatermToggle', 'floaterm' ])
    endif
endfunction
